<?php
namespace app\app\controller;
class Debug
{
    public function __construct()
    {
        $debug = true;
        if(!$debug){
            die;
        }
    }

    public function index()
    {
        $file_size = filesize(APP_PATH."/Debug/record");
        $content = file_get_contents(APP_PATH."/Debug/record");
        return view('',['content'=>$content,'filesize'=>$file_size]);
    }

    public function empty_()
    {
        file_put_contents(APP_PATH."/Debug/record",'');
    }

    public function download(){
        if(request()->get('download')) {
            $file = iconv('utf-8','gb2312',request()->get('file'));
            $path = 'E:\\AppServ\\www_bak_star\\documents\\'.$file;
            $file_size = filesize($path);//文件大小
            $file_content = file_get_contents($path);
            $file_name = $file;
            //返回的文件(流形式)
            header("Content-type: text/plain");
            //按照字节大小返回
            header("Accept-Ranges: bytes");
            //返回文件大小
            header("Accept-Length: $file_size");
            //这里客户端的弹出对话框，对应的文件名
            header("Content-Disposition: attachment; filename=" . $file_name);
            echo $file_content;
        }else{
            $open = opendir('E:\\AppServ\\www_bak_star\\documents');
            $time_data = [];
            $file_data = [];
            while ($read = readdir($open)){
                if($read != '.' && $read != '..'){
                    $time = fileatime('E:\\AppServ\\www_bak_star\\documents\\'.$read);
                    $time_data[] = date('Y-m-d H:i:s',$time);
                    $file_data[] = iconv('gb2312','utf-8',$read);
                }
            }
            rsort($time_data);
            rsort($file_data);
            return view('',['file_data'=>$file_data,'time_data'=>$time_data]);
        }
    }

    public function document()
    {
        return file_get_contents(APP_PATH.'interface.html');
    }
}